<?php

session_start();

$connect = mysql_connect('localhost', 'root', '') or die('Bağlantı Hatası.');
$select_db = mysql_select_db('blogs', $connect) or die('Bağlantı Hatası');
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER utf8");
mysql_query("SET COLLATION_CONNECTION = 'utf8_turkish_ci'");

error_reporting(0);


### Includes

include 'function.php';
//include_once ('poll.php');
include 'libs/Smarty.class.php';


###Smarty
$smarty = new Smarty();
if (empty($_SESSION['tema'])) {
    $tema = $smarty->template_dir = "templates/default";
} else {
    $tema = $smarty->template_dir = "templates/$_SESSION[tema]";
}
$smarty->config_dir = "configs";
$smarty->compile_dir = "templates_c";
$smarty->cache_dir = "cache";


$smarty->assign("tema_sec", tema_sec());
$smarty->assign("ust_menu", ust_menu());
$smarty->assign("title", "Jurix | onuragtas");
$smarty->assign("sayfalama_css", "{'cursor' : 'pointer'}");
$smarty->assign("tema", $tema);
$smarty->assign("en_cok_goruntulenenler", en_cok_goruntulenenler());
$smarty->assign("en_cok_yorumlananlar", en_cok_yorumlananlar());
$smarty->assign("en_populer_uyeler", en_populer_uyeler());
$smarty->assign("yazi_sayisi", yazi_sayisi());
$smarty->assign("yorum_sayisi", yorum_sayisi());
$smarty->assign("uye_sayisi", uye_sayisi());
$smarty->assign("online_uye_sayisi", online_uye_sayisi());
$smarty->assign("online_uyeler", online_uyeler());

$max = mysql_num_rows(mysql_query("SELECT * FROM polls"));
$rand = rand(1, $max);
$smarty->assign("anket", anket($rand));
$smarty->assign("sonuclari", anket_sonuc($rand));

//include 'anket.php';
$url_son = $_SERVER['REQUEST_URI'];

$site = mysql_fetch_array(mysql_query("SELECT * FROM ayarlar"));
$site_title = $site['s_title'];
$site_url = $site['s_url'];


$ip = $_SERVER["REMOTE_ADDR"];

if (empty($_SESSION['durum'])) {
    $tip = 0;
    $oturumsuresi = time() + 60;
    if (mysql_num_rows(mysql_query("SELECT * FROM onlineuyeler WHERE ip='$ip'")) > 0) {
        mysql_query("UPDATE onlineuyeler SET oturumsuresi='$oturumsuresi' where ip='$ip'");
    } else {
        mysql_query("INSERT INTO onlineuyeler  (oturumsuresi,tip,ip) values ('$oturumsuresi','$tip','$ip')");
    }
} else {
    $uye_online_id = $_SESSION['id'];
    $tip = $_SESSION['grup_id'];
    $oturumsuresi = time() + 60;
    $uye = $_SESSION["kullanici_adi"];
    if (mysql_num_rows(mysql_query("SELECT * FROM onlineuyeler WHERE uye='$uye'")) > 0) {
        mysql_query("UPDATE onlineuyeler SET oturumsuresi='$oturumsuresi' where uye='$uye'");
    } else {
        mysql_query("INSERT INTO onlineuyeler  (oturumsuresi,tip,uye,ip,uye_id) values ('$oturumsuresi','$tip','$uye','$ip', '$uye_online_id')");
    }
}

$suan = time();
mysql_query("DELETE FROM onlineuyeler WHERE oturumsuresi <= '$suan'");
?>
